package com.tedu.parkinglot.parklot.service.impl;

import com.tedu.parkinglot.parklot.mapper.ParklotMapper;
import com.tedu.parkinglot.parklot.pojo.dto.ParklotQuery;
import com.tedu.parkinglot.parklot.pojo.dto.ParklotSaveParam;
import com.tedu.parkinglot.parklot.pojo.entity.ParklotAdmin;
import com.tedu.parkinglot.parklot.pojo.vo.ParklotVO;
import com.tedu.parkinglot.parklot.service.ParklotService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Slf4j
@Service
public class ParklotServiceImpl implements ParklotService {
    @Autowired
    ParklotMapper parklotMapper;

    @Override
    public List<ParklotVO> select(ParklotQuery parklotQuery) {
        log.debug("查询参数：{}", parklotQuery);
        List<ParklotVO> list = parklotMapper.select(parklotQuery);
        log.debug("查询结果：{}", list);
        return list;
    }

    @Override
    public void save(ParklotSaveParam parklotSaveParam) {
        log.debug("新增参数：{}", parklotSaveParam);
        ParklotAdmin parklotAdmin = new ParklotAdmin();
        BeanUtils.copyProperties(parklotSaveParam, parklotAdmin);
        if (parklotAdmin.getId()==null){
            parklotAdmin.setCreateTime(new Date());
            parklotAdmin.setOccupySpace(0);
            parklotMapper.insert(parklotAdmin);
        }else {
            parklotAdmin.setUpdateTime(new Date());
            parklotMapper.update(parklotAdmin);
        }
    }

    @Override
    public void deleteParking(Long id) {
        log.debug("删除参数：{}", id);
        parklotMapper.deleteParking(id);
    }
}
